package com.example.my.shop.mybatis.controller;


import com.example.my.shop.mybatis.service.TbUserService;
import com.example.my.shop.mybatis.service.impl.TbUserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

 /**
  * @ProjectName:
  * @Package:        com.example.my.shop.mybatis.controller
  * @ClassName:      User_deleteById
  * @Description:    删除用户信息功能
  * @Author:         Mr.Vincent
  * @CreateDate:     2019/6/1 15:12
  * @Version:        1.0.0
  */
@WebServlet(value = "/deleteById")
public class User_deleteById extends HttpServlet {

    /**
     * @Method:        service
     * @Description:    根据id删除用户
     * @Param:         [req, resp]
     * @return:        void
     * @Author:        Mr.Vincent
     * @Date:          2019/6/1
     */
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");

        TbUserService tbUserService = new TbUserServiceImpl();
        int i = tbUserService.deleteById(Long.parseLong(id));
        if(i>0){
            req.setAttribute("message","删除成功！！！");
        }else{
            req.setAttribute("message","删除失败！！！");
        }
        req.getRequestDispatcher("/user_list").forward(req,resp);
    }
}
